﻿using UnityEngine;
using System.Collections;

public class RhombusBlockComponent : MonoBehaviour
{
    MeshRenderer colorMat;

    static Color normalColor = Color.white;

    static Color blockColor = Color.yellow;

    static Color canColor = Color.green + new Color(0, -0.8f, 0, -0.5f);

    static Color hintcanColor = Color.green;

    static Color hintcantColor = Color.red;

    private void Start()
    {
        GetMeshRenderer();

        ////  文字
        //Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position);
        //rect.x = screenPos.x + 25;
        //rect.y = Screen.height - screenPos.y - 25;
        //rect.width = 256;
        //rect.height = 50;

        SetEnable(false);
    }

    void GetMeshRenderer()
    {
        if (colorMat == null)
        {
            colorMat = GetComponent<MeshRenderer>();
            colorMat.enabled = _Enable;
        }

    }

    public int _Order = -1;

    int _Status = 0;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="flag">0 空闲; 1 占位</param>
    public void SetStatus(int flag)
    {
        GetMeshRenderer();

        _Status = flag;

        switch (flag)
        {
            case 0:
                colorMat.material.color = normalColor;
                break;
            case 1:
                colorMat.material.color = blockColor;
                break;
            case 2:
                colorMat.material.color = canColor;
                break;
            case 3:
                colorMat.material.color = hintcanColor;
                break;
            case 4:
                colorMat.material.color = hintcantColor;
                break;
        }
    }

    bool _Enable = false;

    public void SetEnable(bool flag)
    {
        GetMeshRenderer();

        _Enable = flag;

        colorMat.enabled = flag;

        //  文字
        screenPos = Camera.main.WorldToScreenPoint(transform.position);
        rect.x = screenPos.x + 25;
        rect.y = Screen.height - screenPos.y - 25;
        rect.width = 256;
        rect.height = 50;

    }

    private Rect rect = new Rect();

    private Vector3 screenPos;
#if DEBUG
    //private void OnGUI()
    //{
    //    if (!_Enable)
    //        return;

    //    GUI.skin.label.normal.textColor = Color.black;
    //    GUI.Label(rect, _Order.ToString());
    //    //GUI.Label(rect, _Order.ToString() + "->" + _Status.ToString());
    //}
#endif
}
